<?php 
require APP_PATH . '/vendor/autoload.php'; 

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

function send_sms($mobile,$code){
    AlibabaCloud::accessKeyClient('LTAIaRSZS7tUkGS7', 'iDkt1WIKXOVTP3lai0SoN9DRVRblxh')
                        ->regionId('cn-hangzhou')
                        ->asDefaultClient();

    try {
        $result = AlibabaCloud::rpc()
                            ->product('Dysmsapi')
                            ->scheme('https') // https | http
                            ->version('2017-05-25')
                            ->action('SendSms')
                            ->method('POST')
                            ->host('dysmsapi.aliyuncs.com')
                            ->options([
                                        'query' => [
                                            'RegionId' => "cn-hangzhou",
                                            'PhoneNumbers' => $mobile,
                                            'SignName' => "搜企企",
                                            'TemplateCode' => 'SMS_175370287',
                                            'TemplateParam' => xn_json_encode(array('code'=> $code))
                                        ],
                                    ])
                            ->request();
        $result =  $result->toArray();
        if($result['Code'] == 'OK'){
            return TRUE;
        } else {
            return $result['Code'];
        }
    } catch (ClientException $e) {
        return $e->getErrorMessage();
    } catch (ServerException $e) {
        return $e->getErrorMessage();
    }
}




?>